/**
  ******************************************************************************
  * @file    lin.h
  * @author  hyseim software Team
  * @date    18-Aug-2023
  * @brief   This file provides all the tmp functions.
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2020 Hyseim. Co., Ltd.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */


/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __LIN_H__
#define __LIN_H__

/* Includes ------------------------------------------------------------------*/
#include "utils.h"

#ifdef __cplusplus
 extern "C" {
#endif

/** @addtogroup IM110GW_LIN_Driver
  * @{
  */

/** @addtogroup LIN
  * @{
  */


/* ================================================================================ */
/* ==============         Local Interconnect Network (LIN)            ============= */
/* ================================================================================ */
typedef struct
{
    __IO uint32_t CON;                              /*!< lIN Control Register,                                           Address offset: 0x000 */
    __IO uint32_t INTR_STAT;                         /*!< Clear Interrupt Register,                                       Address offset: 0x004 */
} LIN_t;


#define LIN0      ((LIN_t*)&(((ASSI_t*)ASSI(0))->lin))
#define LIN1      ((LIN_t*)&(((ASSI_t*)ASSI(1))->lin))
#define LIN2      ((LIN_t*)&(((ASSI_t*)ASSI(2))->lin))
#define LIN3      ((LIN_t*)&(((ASSI_t*)ASSI(3))->lin))
#define LIN4      ((LIN_t*)&(((ASSI_t*)ASSI(4))->lin))
#define LIN5      ((LIN_t*)&(((ASSI_t*)ASSI(5))->lin))
#define LIN6      ((LIN_t*)&(((ASSI_t*)ASSI(6))->lin))
#define LIN7      ((LIN_t*)&(((ASSI_t*)ASSI(7))->lin))


/*-------------------------------------------------------------------------------------------------------*/
/*---                                Local Interconnect Network (LIN)                                 ---*/
/*-------------------------------------------------------------------------------------------------------*/
/******************************    Bit definition for LIN_CON register   *********************************/
#define LIN_CON_ENABLE                         (0x1U << 0)                /*!< LIN Enable. */
#define LIN_CON_TXEN                           (0x1U << 1)                /*!< Transmitter Block Enable. */
#define LIN_CON_RXEN                           (0x1U << 2)                /*!< Receiver  Block Enable. */
#define LIN_CON_TXOIE                          (0x1U << 3)                /*!< Transmit Over Interrupt Enable. */
#define LIN_CON_RXOIE                          (0x1U << 4)                /*!< Receive  Over Interrupt Enable. */
#define LIN_CON_RXEIE                          (0x1U << 5)                /*!< Receive  Error Interrupt Enable. */
#define LIN_CON_LOOPEN                         (0x1U << 6)                /*!< Loop Back Mode Enable. */

/******************************    Bit definition for LIN_CLR_INTR register   ***************************/
#define LIN_INTR_STAT_TX_OVER                   (0x1U << 3)                /*!< Set if the LIN controller succeeds in sending the synch break.Write 1 to Clear this inturrupt. */
#define LIN_INTR_STAT_RX_OVER                   (0x1U << 4)                /*!< Set if the LIN controller succeeds in Receiving the synch break.Write 1 to Clear this inturrupt. */
#define LIN_INTR_STAT_RX_ERR                    (0x1U << 5)                /*!< Set if the received synch break is greater than 13 bit.Write 1 to Clear this inturrupt. */

/*----------------------------------------------------------------------------*/
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/

/** @defgroup LIN_Exported_Constants
  * @{
  */
#define LIN_IT_TX_OVER                          LIN_INTR_STAT_TX_OVER
#define LIN_IT_RX_OVER                          LIN_INTR_STAT_RX_OVER
#define LIN_IT_RX_ERROR                         LIN_INTR_STAT_RX_ERR 

#define LIN_SyncBreak_BitNum_Mask               (0xFU << 12)
#define LIN_SyncBreak_BitNum_11b                (11U  << 12)
#define LIN_SyncBreak_BitNum_12b                (12U  << 12)
#define LIN_SyncBreak_BitNum_13b                (13U  << 12)
#define LIN_SyncBreak_BitNum_14b                (14U  << 12)

#define LIN_SyncBreak_OneBitBclkNum_Mask        (0xFFFFU << 16)
#define LIN_SyncBreak_OneBitBclkNum_16          (15U  << 16)
/**
  * @}
  */

/* Exported macro ------------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/

void LIN_Cmd(LIN_t* LINx, FunctionalState_t NewState);
void LIN_LoopBackCmd(LIN_t* LINx, FunctionalState_t NewState);
void LIN_ReceiverCmd(LIN_t* LINx, FunctionalState_t NewState);
void LIN_TransmitterCmd(LIN_t* LINx, FunctionalState_t NewState);
void LIN_OneBitBclkNumConfig(LIN_t* LINx, uint32_t BclkNum);
void LIN_BitNumConfig(LIN_t* LINx, uint32_t BitNum);
void LIN_ITConfig(LIN_t* LINx, uint32_t LIN_IT, FunctionalState_t NewState);
ITStatus_t LIN_GetITStatus(LIN_t* LINx, uint32_t LIN_IT);
void LIN_ClearIT(LIN_t* LINx, uint32_t LIN_IT);

/**
  * @}
  */

/**
  * @}
  */

#ifdef __cplusplus
}
#endif

#endif /* __IM110GW_LIN_H */
